/********************************************************************************
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later 	*
* version. This program is distributed in the hope that it will be useful, but 	*
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more *
* details. You should have received a copy of the GNU General Public License 	*
* along with this program; if not, write to the Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.						*
* (c) Copyright 2012 José Delgado Pérez, josedelgado@ula.ve josed43@gmail.com.	*				*
********************************************************************************/

/**
 @file comunicacionSerial.cpp
 @brief Se implementan los métodos para el manejo de la comunicación Serial de la clase COMUNICACIONSERIAL_H_.
 @date Diciembre, 2012.
 @author José Delgado Pérez, josedelgado@ula.ve josed43@gmail.com.
 @version 0.9
*/

#include <Arduino.h>
#include "comunicacionSerial.h"
#include "definicion.h"

/****** Métodos de manejo de la comunicación serial en la plataforma LASDAI-LR2 ******/

comunicacionSerial::comunicacionSerial() {

}

/**************************************************************************************************/

comunicacionSerial::comunicacionSerial(unsigned long int baudios) {
	Serial.begin(baudios);
}

/**************************************************************************************************/

void comunicacionSerial::iniciarComunicacion(unsigned long int baudios) {
	Serial.begin(baudios);
}

/**************************************************************************************************/

void comunicacionSerial::escribirDatos(uint8_t nBytes, uint8_t *sbuf) {
	for (int i = 0; i < nBytes; ++i) {
		Serial.write(sbuf[i]);
	}
}

/**************************************************************************************************/

void comunicacionSerial::leerDatos(char finComando, char* sbuf, int sizeComando) {
	Serial.readBytesUntil(finComando, sbuf, sizeComando);
}

/**************************************************************************************************/

void comunicacionSerial::limpiarBufer(){
	Serial.flush();
}

/**************************************************************************************************/

bool comunicacionSerial::verificarBufer() {
	if(Serial.available() > 0){
		return true;
	}else{
		return false;
	}
}

/**************************************************************************************************/

comunicacionSerial::~comunicacionSerial() {

}
